#!/usr/local/bin/python3
# -*- coding: UTF-8 -*- 
import os
import json
import sys
import shutil
import zipfile

def all_path(dirname):
    result = []
    for maindir, subdir, file_name_list in os.walk(dirname):
        for filename in file_name_list:
            apath = os.path.join(maindir, filename)
            result.append(apath)
    return result

def GetExtNamesList(fileslist,ext):
    filenames=[]
    for file in fileslist:
        fileinfo=os.path.splitext(file)
        if fileinfo[1]==ext:
            filenames.append(file)
    return filenames

def copyFile(sourcefolder,desfolder,fileType):
    filelist=GetExtNamesList(all_path(sourcefolder),fileType)
    for file in filelist:
        # print(file)
        desfilename=file.replace('\\','/').replace(sourcefolder,desfolder)
        # print(desfilename)
        if not os.path.exists(os.path.dirname(desfilename)):
            os.makedirs(os.path.dirname(desfilename))
        if not os.path.exists(desfilename):
            shutil.copy(file,desfilename)

def copySpecialFile(sourcefolder,desfolder,fileType):
    copyFile(sourcefolder,desfolder,fileType)